#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node {
	int index, val, color;
} a[100005];

signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		a[i].index = i;
	for (int i = 1; i <= n; i++)
		cin >> a[i].val;
	for (int i = 1; i <= n; i++)
		cin >> a[i].color;

	sort(a + 1, a + n + 1, [](node x, node y) {
		if (x.color != y.color)
			return x.color < y.color;
		else
			return x.index < y.index;
	});

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (a[i].color != a[j].color)
				break;
			if ((a[j].index - a[i].index) % 2 == 0)
				ans += (a[j].index + a[i].index) * (a[j].val + a[i].val) % 10007;
		}
	}
	cout << ans % 10007;
	return 0;
}
